﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace NuMvvm.Services
{
    public class DialogService : IDialogService
    {
        public Task ShowAsync(string text, string title)
        {
            return Task.Run(() => MessageBox.Show(text, title));
        }

        public Task ShowErrorAsync(string text, string title)
        {
            return Task.Run(() => MessageBox.Show(text, title, MessageBoxButton.OK, MessageBoxImage.Error));
        }

        public Task ShowInfoAsync(string text, string title)
        {
            return Task.Run(() => MessageBox.Show(text, title, MessageBoxButton.OK, MessageBoxImage.Information));
        }

        public Task ShowWarningAsync(string text, string title)
        {
            return Task.Run(() => MessageBox.Show(text, title, MessageBoxButton.OK, MessageBoxImage.Warning));
        }

        public Task<bool?> ShowYesNoAsync(string text, string title)
        {
            return Task.Run(() => ToResult(MessageBox.Show(text, title, MessageBoxButton.YesNo, MessageBoxImage.Question)));
        }

        public Task<bool?> ShowYesNoCancelAsync(string text, string title)
        {
            return Task.Run(() => ToResult(MessageBox.Show(text, title, MessageBoxButton.YesNoCancel, MessageBoxImage.Error)));
        }

        private bool? ToResult(MessageBoxResult messageBoxResult)
        {
            switch (messageBoxResult)
            {
                case MessageBoxResult.Yes: return true;
                case MessageBoxResult.No: return false;
            }

            return null;
        }
    }
}
